package com.xique.door.controller;

import com.xique.common.core.domain.R;
import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.door.bean.domain.Repair;
import com.xique.door.service.IRepairService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/repair")
public class RepairController {
  @Autowired private IRepairService repairService;

  /** 报修列表 */
  @PreAuthorize(hasPermi = "door:repair:list")
  @GetMapping("/repairList")
  public R getRepairList(Integer pageNum, Integer pageSize,String name,String status, String startTime,
                         String endTime) {
    Long parkId = SecurityUtils.getParkId();
    pageNum = pageNum != null ? pageNum : 1;
    pageSize = pageSize != null ? pageSize : 10;
    if (parkId != null) {
      return R.ok(repairService.getRepairList(parkId, pageNum, pageSize,name,status,startTime,endTime));
    } else {
      return R.fail("接口传入的parkId为空");
    }
  }
  /** 修改报修状态 */
  @PreAuthorize(hasPermi = "door:repair:edit")
  @PutMapping("/repairStatus")
  public R updateRepair(@RequestBody Repair repair) {
    Long parkId = SecurityUtils.getParkId();
    if (parkId != null) {
      repair.setParkId(parkId);
      repair.setUpdateTime(new Date());
      return repairService.updateRepair(repair);
    } else {
      return R.fail("接口传入的parkId为空");
    }
  }
  /** 报修详情 */
  @PreAuthorize(hasPermi = "door:repair:edit")
  @GetMapping("/repairDetails")
  public R getRepair(Long id) {
    Repair repair = repairService.getRepair(id);
    return R.ok(repair);
  }

}
